import { getListApi } from "@/api/configCenter/outBoundAgent";
import { reactive, ref } from "vue";

export default function InitHook() {
  const formDataRef = ref<any>(null);
  const formState = reactive<DepartmentPersonnel.CompanyInfoForm>({
    id: "",
    typeValue: [],
    companyName: "",
    shortName: "",
    waybillPrefix: "",
    phone: "",
    provinceCode: "",
    provinceName: "",
    cityCode: "",
    cityName: "",
    areaCode: "",
    areaName: "",
    logUrls: [],
    companyNameEn: "",
    companyAddressDetails: "",
    dataScope: "",
    // bizDeptAccountReqDtoList: [
    //   {
    //     name: "",
    //     bankName: "",
    //     receiveAccount: "",
    //     isDefault: 1,
    //     sisterBankNum: ""
    //   }
    // ],
    bizDeptApiConfigReqDtoList: [
      {
        platformId: "",
        platformName: "",
        agentId: "",
        agent: "",
        apiKey: "",
        domainName: "",
        userName: ""
      }
    ]
  });
  const loading = ref<boolean>(false);
  const outBoundAgentOpts = ref<Base.GeneraDataType[]>([]);
  const filter = (inputValue: string, path: Array<Base.GeneraDataType>) => {
    return path.some(option => option.name.toLowerCase().indexOf(inputValue.toLowerCase()) > -1);
  };
  const getAllAgent = () => {
    return getListApi({ pageNum: 1, pageSize: 999999, status: 1 } as OutBoundAgent.SearchForm).then((res: any) => {
      const { code, data } = res;
      if (code === 200) {
        outBoundAgentOpts.value = data.records || [];
      }
    });
  };
  return {
    formState,
    formDataRef,
    loading,
    filter,
    getAllAgent,
    outBoundAgentOpts
  };
}
